oa.MemoryModeEL = {
  noInformationDisclosed : 0,
  differentCardBackForExprAndValue : 1,
  randomSelectionVisible : 2,
  allExpressionsVisible : 3,
  allValuesVisible : 4
};
/**
 * Render the structure of a memory grid and fill it.
 * Can be used for matching binary standard problems with their answer
 * or for matching natural numbers with equivalent visualizations
 * or for matching proper fractions with equivalent visualizations
 * or for matching equivalent fractions.
 * 
 * @author Gerd Wagner
 */
oa.rf.memory = new RenderingForm(
  "memory",
  "This rendering form uses a memory/concentration game grid for rendering several kinds of problems in the form of matching problems where the learner has to find the right pairs. Can be used for matching binary expressions with their evaluation result, natural numbers with equivalent visualizations, proper fractions with equivalent visualizations, or for matching equivalent fractions.",
  RenderingModeEL.enbloc,
  "Choose a card and then try to find a match.",  // help text
  true  // no evaluation!
  );
oa.rf.memory.isApplicableTo = function (apt) {
  return (
    apt instanceof ArithmeticProblemType && 
     (apt.numberType === NumberTypeEL.NonNegativeInteger || 
      apt.numberType === NumberTypeEL.Integer ||
      apt.numberType === NumberTypeEL.Decimal) &&
     apt.operators.length === 1 
  );
};
/**
 * Global variables
 */
oa.rf.memory.selectedCards = 0;
oa.rf.memory.firstCardEl = null;
oa.rf.memory.secondCardEl = null;
/**
 * Compute a suitable size of a Memory grid as close to a square as possible
 * 
 * @author Gerd Wagner
 * @param {number} n  The number of grid cells.
 */
oa.rf.memory.computeGridSize = function (n) {
  var k = Math.floor( Math.sqrt(n));
  while (n%k !== 0) k=k-1;
  oa.rf.memory.height = k;
  oa.rf.memory.width = parseInt( n/k);
};
/**
 * Check if two cards form a valid pair
 * 
 * @author Gerd Wagner
 * @param {object} c1  First card.
 * @param {object} c2  Second card.
 */
oa.rf.memory.isValidCardPair = function (c1,c2) {
  var res = 
    ( c1.pairNo === c2.pairNo ||
       ( c1.value === c2.value &&
         ( util.containsArithmeticOperator( c1.content) &&
             !util.containsArithmeticOperator( c2.content) ||
           util.containsArithmeticOperator( c2.content) &&
             !util.containsArithmeticOperator( c1.content) ) ) 
    );
  return res;
};
